package com.agan.agangame.dto;

/**
 * @author cg
 * @title: CsspReturnCode
 * @description: 统一返回吗枚举类
 * @date 2020/7/25 2:31 PM
 */
public enum ReturnCodeEnum {

    /**
     * 成功
     */

    SUCCESS("0","成功"),

    /**
     * 失败
     */

    FILURE("400","失败"),

    /**
     * 参数错误
     */

    GEN_PARAMETER_ERROR("401","参数错误"),

    /**
     * 签名校验错误
     */
    GEN_SIGNATURE_ERROR("402","签名校验错误"),

    /**
     * 服务器内部错误
     */
    SYSTEM_ERROR("500","亲，请稍后再试");


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    private String code;

    private String message;


    ReturnCodeEnum(String code, String message){
        this.code =code;
        this.message =message;
    }

    /**
     * 循环
     * @param code
     * @return
     */
    public static ReturnCodeEnum getByCode(String code){
        for (ReturnCodeEnum type : ReturnCodeEnum.values()){
            if(type.getCode().equals(code)){
                return type;
            }
        }
        return ReturnCodeEnum.FILURE;
    }

    /**
     * @param code
     * @return
     */
    public static String getMessageByCode(String code){
        for (ReturnCodeEnum type : ReturnCodeEnum.values()){
            if(type.getCode().equals(code)){
                return type.getMessage();
            }
        }
        return ReturnCodeEnum.FILURE.getMessage();
    }

}
